package com.hoshiicloud.saleorder.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hoshiicloud.common.rpc.Response;
import com.hoshiicloud.saleorder.dto.DispatchBillAndDetailDTO;
import com.hoshiicloud.saleorder.dto.OrderCalcDTO;
import com.hoshiicloud.saleorder.dto.OrderDTO;
import com.hoshiicloud.saleorder.dto.OrderMultiConditionDTO;
import com.hoshiicloud.saleorder.dto.PayResultDTO;
import com.hoshiicloud.saleorder.dto.PoBillDTO;
import com.hoshiicloud.saleorder.entity.OrderInfo;
import com.hoshiicloud.saleorder.entity.OrderMain;
import com.hoshiicloud.saleorder.param.BranchOrderQueryParam;
import com.hoshiicloud.saleorder.param.OrderCalcParam;
import com.hoshiicloud.saleorder.param.OrderMainQueryParam;
import com.hoshiicloud.saleorder.param.OrderMainStatusUpdateParam;
import com.hoshiicloud.saleorder.param.OrderSubmitParam;
import com.hoshiicloud.saleorder.param.PayOrderParam;
import com.hoshiicloud.saleorder.param.RefundOrderPayParam;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 销售订单业务服务接口
 */
public interface SaleOrderService {

    /**
     * 计算订单金额
     *
     * @param param
     * @return
     */
    OrderCalcDTO calcOrder(OrderCalcParam param);

    /**
     * 提交订单
     *
     * @param param
     * @return
     */
    Response submitOrder(OrderSubmitParam param);

    /**
     * 订单支付
     *
     * @param param
     * @return
     */
    PayResultDTO payOrder(PayOrderParam param);

    /**
     * 取消订单
     *
     * @param orderId
     * @return
     */
    boolean cancelOrder(Long orderId);

    /**
     * 批量取消订单
     * @param orderIds
     * @return
     */
    boolean batchCancelOrders(List<Long> orderIds);

    /**
     * 退款订单
     *
     * @param param
     * @return
     */
    boolean refundOrder(RefundOrderPayParam param);

    /**
     * 删除订单
     *
     * @param orderId
     * @return
     */
    boolean deleteOrder(Long orderId);

    /**
     * 发送消息
     *
     * @return
     */
    void sendMsg(PoBillDTO poBillDTO);

    /**
     * 订单列表
     *
     * @param page
     * @param queryWrapper
     * @return
     */
    Response<Page<OrderDTO>> listOrder(Page page, QueryWrapper<OrderMain> queryWrapper);

    /**
     * 所有订单列表
     * @param queryWrapper 查询参数
     * @return Response<List<OrderDTO>>
     */
    Response<List<OrderDTO>> listAllOrders(QueryWrapper<OrderMain> queryWrapper);

    /**
     * 订单详情
     *
     * @param orderId
     * @return
     */
    Response viewOrder(Long orderId);

    /**
     * 核销订单
     *
     * @param orderId
     * @return
     */
    Response verificationOrder(Long orderId);

    /**
     * 核销订单
     *
     * @param orderIds
     * @return
     */
    Response verificationBatchOrder(List<Long> orderIds);

    /**
     * 更新订单状态
     *
     * @param param
     * @return
     */
    Response updateOrderStatus(OrderMainStatusUpdateParam param);

    /**
     * 查询商品购买记录
     *
     * @param page 分页参数
     * @param queryWrapper 查询条件
     * @return Response<Page < Map < String, Object>>>
     */
    Response<Page<Map<String, Object>>> queryOrdersWithUserInfo(Page page, QueryWrapper<OrderInfo> queryWrapper);

    /**
     * 多条件查询订单列表
     *
     * @param page IPage
     * @param param OrderMainQueryParam
     * @param key String
     * @param httpServletRequest httpServletRequest
     * @return IPage<OrderMultiConditionDTO>
     */
    Page<OrderMultiConditionDTO> multiConditionQueryOrderPage(Page<OrderMultiConditionDTO> page,
            OrderMainQueryParam param, HttpServletRequest httpServletRequest,
            String key);

    /**
     * 查询订单详情
     *
     * @param orderMainNo orderMainNo
     * @return OrderMultiConditionDTO
     */
    OrderMultiConditionDTO orderDetailsQuery(String orderMainNo, String shippingId);


    /**
     * 分店订单导出
     *
     * @param redisKey redisKey
     * @param response response return ServletOutputStream
     */
    ServletOutputStream branchOrdersExcelExport(String redisKey, HttpServletResponse response);

    /**
     * 获得订单导出key
     *
     * @param branchOrderQueryParam branchOrderQueryParam
     * @param httpServletRequest httpServletRequest
     * @return redisKey
     */
    void getExportRedisKey(BranchOrderQueryParam branchOrderQueryParam, HttpServletRequest httpServletRequest,
            String redisKey);


    /**
     * 分店订单列表
     *
     * @param branchOrderQueryParam branchOrderQueryParam
     * @param page page
     * @return List
     */
    Page multiConditionBranchOrders(BranchOrderQueryParam branchOrderQueryParam, Page page,
            HttpServletRequest httpServletRequest);

    /**
     * 判断Redis的Key是否产生
     *
     * @param key key
     * @return boolean
     */
    boolean getRedisHasKey(String key);

    /**
     * 得到分店订单所有的信息
     *
     * @param branchOrderQueryParam branchOrderQueryParam
     * @return List
     */
    List<Map<String, Object>> getOrderInfoAllMessage(BranchOrderQueryParam branchOrderQueryParam);

    /**
     * 添加出货单
     *
     * @param dispatchBillAndDetailDTO dispatchBillAndDetailDTO
     * @param httpServletRequest httpServletRequest
     */
    void addDispatchBill(DispatchBillAndDetailDTO dispatchBillAndDetailDTO, HttpServletRequest httpServletRequest);
}
